package com.Mt.Controller;

import com.Mt.Dto.Dto;
import com.Mt.Service.Mt_UserMoneyService;
import com.Mt.Utils.DtoUtil;
import com.Mt.pojo.Mt_Money;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("Money")
public class Mt_UserMoneyController {
    @Reference
    private Mt_UserMoneyService userMoneyService;

    /**
     * 用户余额
     * @param userid
     * @return
     */
    @GetMapping("userMoney/{userid}")
    public Dto  userMoney(@PathVariable("userid") String userid){
         Mt_Money mt_Money = userMoneyService.queryById(userid);

          return DtoUtil.returnSuccessData(mt_Money);
    }

    /**
     * 新用户
     */

    @GetMapping("newmoney/{userid}")
    public Dto newmoney(@PathVariable("userid") String userid){
        int result = userMoneyService.newMoney(userid);
        if (result > 0) {
            return  DtoUtil.returnSuccess();
        }else {
            return DtoUtil.returnError(5001,"未知错误");
        }
    }
    /**
     * 充钱100元子
     */
    @GetMapping("cq/{userid}")
    public Dto cq(@PathVariable("userid") String userid){
        int res = userMoneyService.cq(userid);
        if (res > 0) {
            return DtoUtil.returnSuccess();
        }else {
            return DtoUtil.returnError(6002,"充值失败");
        }
    }

    /**
     * 消费
     */
    @GetMapping("shopping/{userid}/{price}")
    public Dto shopping(@PathVariable("userid") String userid ,@PathVariable("price") int price){
        int result = userMoneyService.sopping(userid,price);
        if (result > 0) {
            return DtoUtil.returnSuccess();
        }else {
            return  DtoUtil.returnError(5001,"消费失败");
        }
    }

}
